
  // 引入客户信息弹窗
    jQuery('.btn-find-auditor').on("click", function () {
    	currentAuditor=jQuery(this).prop('id');
        jQuery("#modal-find-auditor").modal('show');
        jQuery("#modal-find-auditor input[type='radio']").attr('checked',false);
    });
    
    
    //选择审批级数时的变化
    
    jQuery('#auditorNumber').change(function(){
    	var n=jQuery(this).val();
    	jQuery("input[name*='ai']").each(function(){
    		var index=jQuery(this).prop('id').substr(-1);
    		var parent=jQuery(this).parent().parent();
    		if(index>n) 
    			parent.addClass('hide');
    		else
    			parent.removeClass('hide');
    	});
    });
    // 提交审批
    jQuery(".app-btn-submit").on('click', function () {
    	var num = jQuery("#auditorNumber").val();
    	var name = jQuery("#name").val();
		for(var i=1;i<=num;i++){
			var val= jQuery("#ai"+i).val();
			if(!val){
				message('审批人没有指定！');
				return;
			}
		}

        $.springLemonDialog({
            content: '确认提交审批：' + quoteForeignName + '？',// 确认文本
            clickButton: function (sender, modal, index) {// 按钮事件处理
                // index:0 确认 1：取消
                // sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
                if (index == 0) {
                	 var d2={
		 						"isNewProduct":jQuery("#isNewProduct").val()
		 				};
		 				var url2 = window.rootPath + '/api/quoteForeigns/' + quoteForeignId;
		 				jQuery.ajax({
		 					url : encodeURI(url2),
		 					type : 'patch',
		 					data : JSON.stringify(d2),
		 					dataType : 'json',
		 					contentType : 'application/json;charset=utf-8',
		 					success : function() {}
		 				});

 						var url = window.rootPath + "/ui/quote-foreign/audit/" + quoteForeignId+"?name="+name;
 	                    jQuery.post(encodeURI(url), jQuery('#form-quote-foreign').serialize(), function (data) {

 	                            if (data.code == 0) {
 	                                window.location = window.rootPath + "/ui/quote-foreign/";
 	                            }
 	                        }
 					
                    );

                }
                $(this).closeDialog(modal);
            }
        });

    });
    //用户查找弹窗
    var serverUserData = {};
    serverUserTable = jQuery('#table-user').DataTable({
        "serverSide": true,
        "iDisplayLength": 4,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url": window.rootPath + '/ui/user/getpage',
            "data": function (d) {
                return $.extend({}, d, serverUserData);
            }
        },
        columns: [
            {
                // 1序号
                data: null,
                defaultContent: ""
            },
            {// 2姓名
                data: "empLogin.name",
            },
            {// 3性别
                data: 'sex'
            },

            {// 4职务
                data: 'position'
            },
            {// 5销售区域
                data: 'saleArea.superiorArea'
            },
            {//6选择按钮
            	data:null,
            	render:function(){
            		var html="<input type='radio' name='btn-select' class='app-select-user'/>"
            			return html;
            	}
            }
            
        ],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }

            serverUserTable.off('click', 'tr');
            serverUserTable.on('click', 'tr', function (event) {
                event = event || window.event;
                var target = event.target || event.scrElement;
                var data = serverUserTable.row(this).data();

                if (target.className.indexOf('app-select-user') != -1) {
                    onSelectUser(data);
                }
                return;
            });
        }
    });//end of datatable
var selectedUser=null;    
var currentAuditor=null;
var  onSelectUser=function onSelectUser(data){
			selectedUser=data;
    };
    
    //引入用户按钮
    jQuery('#btn-reference').on('click',function(){
        if(selectedUser && currentAuditor){
        	jQuery("#ai"+currentAuditor).val(selectedUser.empLogin.name);
        	jQuery("#auditor"+currentAuditor).val(selectedUser.id);                	
        }
        	
        selectedUser=null;
        currentAuditor=null;
        jQuery("#modal-find-auditor").modal('hide');
    });
    //查找用户返回按钮
    jQuery('.app-find-user-return').on('click',function(){
        selectedUser=null;
        currentAuditor=null;
    });
    //查询
    jQuery('.app-btn-search').on('click',function(){
        serverUserData.key=jQuery("#search").val();
        serverUserTable.draw();
    });
    //撤销查询
    jQuery('.app-btn-reset').on('click',function(){
        jQuery('#search').val('');
        serverUserData.key='';
        serverUserTable.draw();
    });    



//泵table
var serverData = {};
serverData.quoteForeignId=jQuery("#id").val();
    var serverTable;
    jQuery(document).ready(function () {
    	var isPump='true';
        serverTable = jQuery('#mainDeviceTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/quote-foreign/getMainpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                	data: null,
                	defaultContent: ""
                },
                {
                    data: 'productName'
                },
                {
                    data: 'productType'
                },
                {
                    data: 'productModel'
                },
                {
                	data: null,
                	 render: function (data, type, full, meta) {
	                        var dOut;
	                        if (data.isInventory == "1") {
								dOut = '<td class="center" ><span class="badge label-pill label-primary">降库产品</span></td>';
							} else if (data.isInventory == "2"){
								dOut = '<td class="center" ><span class="badge label-pill label-success">被降库</span></td>';
							}else{
								dOut = '<td class="center" ><span class="badge label-pill label-danger">未降库</span></td>';
							}                
	                        return dOut;
	                    }
                },
                {
                	data: 'number'
                },
                {
                	data : 'unit'
                },
                {
                	data: 'costPrice'
                },
                {
                	data: 'unitPrice'
                },
                {
                	data: 'power'
                },
                {
                	data: 'flowMaterial'
                },
                {
                	data: 'transMedia'
                },
                {
                	data: 'viscosity'
                },
                {
                	data: 'flux'
                },
                {
                	data: 'pumpLift'
                },
                {
                	data: 'temperature'
                },
                {
                	data: 'proportion'
                },
                {
                	data: 'inPressure'
                },
                {
                	data: 'effectiveNPSHA'
                },
                {
                	data: 'mustMPSHA'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }

            }
        });
        
        
    });


//其他table
    var serverData1 = {};
    var	serverTable1;
    serverData1.quoteForeignId=jQuery("#id").val();
    jQuery(document).ready(function () {
    	serverTable1 =  jQuery('#otherTable').DataTable({
    		"serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/quote-foreign/getOtherpage',
                "data": function (d) {
                    return $.extend({}, d, serverData1);
                }
            },
            columns: [
                {
                	data: null,
                	defaultContent: ""
                },
                {
                    data: 'deviceName'
                },
                {
                    data: 'type'
                },
                {
                	data: 'material'
                },
                {
                    data: 'unit'
                },
                {
                	data: 'amount'
                },
                {
                	data: 'costPrice'
                },
                {
                	data: 'price'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
    	});
    	
    });
	//查看附件
	jQuery('.attachment').on('click',function(){
		   var quoteForeignId=jQuery("#id").val();
			filedown(quoteForeignId,'外贸价格单附件',0);
	});
   ////获附件数量
    var quoteForeignId=jQuery("#id").val();
	var numId='foreign-quote-ANum';
	if(quoteForeignId!=''){
		showANum(quoteForeignId,'外贸价格单附件',numId);
	}

